#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys,os
lib_path = os.path.abspath('../../')
sys.path.append(lib_path)

from tool_interval import *
import matplotlib.pyplot as plt

c = ['red','green','blue', 'yellow', 'purple', 'orange', 'black', 'pink', 'orange', 'brown']
u = []

s1 = Sequence([(0,10), (12,15), (8,9), (11,13), (6,10)])
a = [s1]
for i in s1.list_intervals :
  a.append(Sequence([i]))
a.append(s1.union())

for _,i in s1.intersections().iteritems() :
  a.append(Sequence(i))

plt.plot()
fig = plt.figure()
ax = fig.add_subplot(111)
x = [0.,0.]

def add_seq_plot(ax, y, sequence) :
  for (start,end) in sequence.list_intervals :
    x[0] = min(x[0], start)
    x[1] = max(x[1], end)
    ax.plot([start,end], [y,y], lw=1, color=c[y])

for i, seq in enumerate(a) :
  ax.text(0, i+0.04, '%s'%(str(seq)))
  add_seq_plot(ax, i, seq)

ax.set_xlim(x[0],x[1])
ax.set_ylim(-0.25, len(a)+0.25)
filename = 'tool_interval.exemple4.png'
plt.savefig(filename)
